// pages/tianjiaJKDA/tianjiaJKDA.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    fileList: [],
    name:'',
    healthStatus:'',
    height:'',
    weight:'',
    bloodType:'',
    negative:'',
    allergic:'',
    previous:'',
    visitDoctor:'',
    familyHistory:''
  },
  onSubmit() {
    // if (this.data.name !== '' && this.data.healthStatus !== '' && this.data.height !== '' && this.data.weight !== '' && this.data.bloodType !== '' && this.data.negative !== '' && this.data.allergic !== '' && this.data.previous !== '' && this.data.visitDoctor !== '' && this.data.familyHistory !== '' ) {
      // 提交表单
      let url = app.globalData.URL + '/healthRecords/addHealthRecords';
      console.log(url);
      let data = {
        userId: app.globalData.user.userId,
        name: this.data.name,
        healthStatus: this.data.healthStatus,
        height: this.data.height,
        weight: this.data.weight,
        bloodType: this.data.bloodType,
        rhNegative: this.data.negative,
        allergyHistory: this.data.allergic,
        pastMedicalHistory: this.data.previous,
        diagnosisHistory: this.data.visitDoctor,
        familyMedicalHistory: this.data.familyHistory
      };
      app.wxRequest('POST', url, data, (res) => {
        console.log("Data submitted:", data);
      }, (err) => {
        console.log(err.errMsg);
      });
    // } else {
    //   wx.showToast({
    //     title: '请完善信息',
    //     icon: 'none',
    //   });
    // }
  },
  onChange1(event) {
    this.setData({
      allergic: event.detail,
      
    });
  },
  onChange2(event) {
    this.setData({
      
      previous: event.detail
      
    });
  },
  onChange3(event) {
    this.setData({
     
      visitDoctor: event.detail,
     
    });
  },
  onChange4(event) {
    this.setData({
      familyHistory: event.detail
    });
  },
  afterRead(event) {
    const {
      file
    } = event.detail;
    // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
    wx.uploadFile({
      url: '', // 仅为示例，非真实的接口地址
      filePath: file.url,
      name: 'file',
      formData: {
        user: 'test'
      },
      success(res) {
        // 上传完成需要更新 fileList
        const {
          fileList = []
        } = this.data;
        fileList.push({
          ...file,
          url: res.data
        });
        this.setData({
          fileList
        });
      },
    });
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})